import Vue from 'vue'
import Router from 'vue-router'
import user from '@/store/modules/user'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import login from '@/views/login/index'
import error from '@/views/404'
import dashboard from '@/views/home/index'
import PerCenter from '@/views/PerCenter'
import employee from '@/views/system/employee/index'
import role from '@/views/system/role/index'
import Permissions from '@/views/system/Permissions/index'
import department from '@/views/system/department/index'
import statistics from '@/views/Attendance/statistics/index'
import recording from '@/views/Attendance/Recording/index'
import information from '@/views/Information/information/index'
import comments from '@/views/Information/comments/index'
import fileupload from '@/views/Cloud-disk/file-upload/index'
import Readwrite from '@/views/Cloud-disk/Read-write/index'



/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: login,
    hidden: true
  },

  {
    path: '/404',
    component: error,
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'system',
    meta: { title: '系统管理', icon: 'el-icon-s-help' },
    children: [
      {
      path: 'dashboard',
      name: 'Dashboard',
      component:dashboard,
      children:[
        {
          path:'/PerCenter',
          name:'PerCenter',
          component:PerCenter,
        },
      ]
      },
      {
        path: '/employee',
        name: 'employee',
        component: employee,
        meta: { title: '员工管理', icon: 'el-icon-user-solid' }
      },
      {
        path: '/role',
        name: 'role',
        component: role,
        meta: { title: '角色管理', icon: 'el-icon-user' }
      },
      {
        path: '/Permissions',
        name: 'Permissions',
        component: Permissions,
        meta: { title: '权限配置', icon: 'el-icon-key' }
      },
      {
        path: '/department',
        name: 'department',
        component: department,
        meta: { title: '部门管理', icon: 'el-icon-copy-document' }
      }
    ]
  },

  {
    path: '/attendance',
    component: Layout,
    redirect: '/statistics',
    name: 'attendance',
    meta: { title: '考勤管理', icon: 'el-icon-s-claim' },
    children: [
      {
        path: '/statistics',
        name: 'statistics',
        component: statistics,
        meta: { title: '员工考勤统计', icon: 'el-icon-s-custom' }
      },
      {
        path: '/recording',
        name: 'recording',
        component: recording,
        meta: { title: '考勤记录查看', icon: 'el-icon-time' }
      },
    ]
  },
  {
    path: '/Information',
    component: Layout,
    redirect: '/information',
    name: 'Information',
    meta: { title: '企业资讯管理', icon: 'el-icon-notebook-2' },
    children: [
      {
        path: '/information',
        name: 'information',
        component: information,
        meta: { title: '资讯信息管理', icon: 'el-icon-message' }
      },
      {
        path: '/comments',
        name: 'comments',
        component: comments,
        meta: { title: '资讯评论发布&管理', icon: 'el-icon-chat-dot-square' }
      },
    ]
  },
  {
    path: '/Cloud-disk',
    component: Layout,
    redirect: '/fileupload',
    name: 'Cloud-disk',
    meta: { title: '云盘文件管理', icon: 'el-icon-cloudy' },
    children: [
      {
        path: '/fileupload',
        name: 'fileupload',
        component: fileupload,
        meta: { title: '文件上传和下载', icon: 'el-icon-folder-add' }
      },
      {
        path: '/Readwrite',
        name: 'Readwrite',
        component: Readwrite,
        meta: { title: '文件读写权限设置', icon: 'el-icon-edit-outline' }
      }

    ]
  },
 
  



  
 


  

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
  
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
});

// router.beforeEach((to,from,next)=>{
//   addRoutes()
  
  
//   })
//   function addRoutes(){
//     let res =  user.state.userdata
//     var data = routesData(res)
//     router.addRoutes(data)
//   }
//   function routesData(result){
//     result.forEach(item=>{
//       routes.push({

//       })
//     })
//     return routes
//   }


const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
